clear all
cd "~/Dropbox/Historical Displacement and Ethnicity - Afghanistan/REPOSITORY/"
use "replication/data/input/MISTI.dta", clear

*------------------------------------------------------------
* Appendix 1.2: Alternative Measure of the Displaced Pashtuns
*------------------------------------------------------------
* Table A3: Cross-tabulation of the original and alternative measures
*   Pearson correlation stated in text in Appendix 1.2 Alternative Measure
corr displaced_pashtun displaced_pashtun2
* Table A3
tabulate displaced_pashtun displaced_pashtun2

*------------------------------------------------------------
* Appendix 2: Details on the Survey Data
*------------------------------------------------------------
* Table A5: Response distribution for the identity-related questions
tabulate d10
* Table A6: Cross-tabulation of ethnic identity and local identity
tabulate ethnic_id local_id

*------------------------------------------------------------
* Identity-related Regression Analyses
*------------------------------------------------------------
* 1. Family identity
    * Original analysis
    reghdfe family_id displaced_pashtun nonpashtun_displaced nonpashtun_nondisplaced female ///
        age unemployed headhousehold married c.householdincome##c.householdincome, ///
        abs(provinceid#wave) vce(cluster distid)
    estimates store m1_1
    mean family_id if nondisplaced_pashtun == 1
    global mean1_1 = r(table)[1,1]

    * Without nondisplaced Pashtuns in the North
    reghdfe family_id displaced_pashtun nonpashtun_displaced nonpashtun_nondisplaced female ///
        age unemployed headhousehold married c.householdincome##c.householdincome if ///
        nondisplaced_pashtun_north == 0, abs(wave) vce(cluster distid)
    estimates store m1_3
    mean family_id if nondisplaced_pashtun_south == 1
    global mean1_3 = r(table)[1,1]

    * Comparing Pashtuns in the North to all others
    reghdfe family_id all_pashtun_north female age unemployed headhousehold married ///
        c.householdincome##c.householdincome, abs(provinceid#wave) vce(cluster distid)
    estimates store m1_4
    mean family_id if all_pashtun_north == 0
    global mean1_4 = r(table)[1,1]

    * Only including Afghanis in the North
    reghdfe family_id displaced_pashtun nonpashtun_displaced female age unemployed ///
        headhousehold married c.householdincome##c.householdincome if north_prov == 1, ///
        abs(provinceid#wave) vce(cluster distid)
    estimates store m1_5
    mean family_id if north_prov == 1 & displaced_pashtun == 0 & nonpashtun_displaced == 0
    global mean1_5 = r(table)[1,1]

    * Alternative measure
    reghdfe family_id displaced_pashtun2 nonpashtun_displaced nonpashtun_nondisplaced ///
        female age unemployed headhousehold married c.householdincome##c.householdincome, ///
        abs(provinceid#wave) vce(cluster distid)
    estimates store m1_6
    mean family_id if pashtun == 1 & displaced_pashtun2 == 0
    global mean1_6 = r(table)[1,1]

* 2. Ethnic identity
    * Original analysis
    reghdfe ethnic_id displaced_pashtun nonpashtun_displaced nonpashtun_nondisplaced female ///
        age unemployed headhousehold married c.householdincome##c.householdincome, ///
        abs(provinceid#wave) vce(cluster distid)
    estimates store m2_1
    mean ethnic_id if nondisplaced_pashtun == 1
    global mean2_1 = r(table)[1,1]

    * Without nondisplaced Pashtuns in the North
    reghdfe ethnic_id displaced_pashtun nonpashtun_displaced nonpashtun_nondisplaced female ///
        age unemployed headhousehold married c.householdincome##c.householdincome if ///
        nondisplaced_pashtun_north == 0, abs(wave) vce(cluster distid)
    estimates store m2_3
    mean ethnic_id if nondisplaced_pashtun_south == 1
    global mean2_3 = r(table)[1,1]

    * Comparing Pashtuns in the North to all others
    reghdfe ethnic_id all_pashtun_north female age unemployed headhousehold married ///
        c.householdincome##c.householdincome, abs(provinceid#wave) vce(cluster distid)
    estimates store m2_4
    mean ethnic_id if all_pashtun_north == 0
    global mean2_4 = r(table)[1,1]

    * Only including Afghanis in the North
    reghdfe ethnic_id displaced_pashtun nonpashtun_displaced female age unemployed ///
        headhousehold married c.householdincome##c.householdincome if north_prov == 1, ///
        abs(provinceid#wave) vce(cluster distid)
    estimates store m2_5
    mean ethnic_id if north_prov == 1 & displaced_pashtun == 0 & nonpashtun_displaced == 0
    global mean2_5 = r(table)[1,1]

    * Alternative measure
    reghdfe ethnic_id displaced_pashtun2 nonpashtun_displaced nonpashtun_nondisplaced ///
        female age unemployed headhousehold married c.householdincome##c.householdincome, ///
        abs(provinceid#wave) vce(cluster distid)
    estimates store m2_6
    mean ethnic_id if pashtun == 1 & displaced_pashtun2 == 0
    global mean2_6 = r(table)[1,1]

* 3. Local identity
    * Original analysis
    reghdfe local_id displaced_pashtun nonpashtun_displaced nonpashtun_nondisplaced female ///
        age unemployed headhousehold married c.householdincome##c.householdincome, ///
        abs(provinceid#wave) vce(cluster distid)
    estimates store m3_1
    mean local_id if nondisplaced_pashtun == 1
    global mean3_1 = r(table)[1,1]

    * Without nondisplaced Pashtuns in the North
    reghdfe local_id displaced_pashtun nonpashtun_displaced nonpashtun_nondisplaced female ///
        age unemployed headhousehold married c.householdincome##c.householdincome if ///
        nondisplaced_pashtun_north == 0, abs(wave) vce(cluster distid)
    estimates store m3_3
    mean local_id if nondisplaced_pashtun_south == 1
    global mean3_3 = r(table)[1,1]

    * Comparing Pashtuns in the North to all others
    reghdfe local_id all_pashtun_north female age unemployed headhousehold married ///
        c.householdincome##c.householdincome, abs(provinceid#wave) vce(cluster distid)
    estimates store m3_4
    mean local_id if all_pashtun_north == 0
    global mean3_4 = r(table)[1,1]

    * Only including Afghanis in the North
    reghdfe local_id displaced_pashtun nonpashtun_displaced female age unemployed ///
        headhousehold married c.householdincome##c.householdincome if north_prov == 1, ///
        abs(provinceid#wave) vce(cluster distid)
    estimates store m3_5
    mean local_id if north_prov == 1 & displaced_pashtun == 0 & nonpashtun_displaced == 0
    global mean3_5 = r(table)[1,1]

    * Alternative measure
    reghdfe local_id displaced_pashtun2 nonpashtun_displaced nonpashtun_nondisplaced ///
        female age unemployed headhousehold married c.householdincome##c.householdincome, ///
        abs(provinceid#wave) vce(cluster distid)
    estimates store m3_6
    mean local_id if pashtun == 1 & displaced_pashtun2 == 0
    global mean3_6 = r(table)[1,1]

* 4. Afghan identity
    * Original analysis
    reghdfe afghan_id displaced_pashtun nonpashtun_displaced nonpashtun_nondisplaced female ///
        age unemployed headhousehold married c.householdincome##c.householdincome, ///
        abs(provinceid#wave) vce(cluster distid)
    estimates store m4_1
    mean afghan_id if nondisplaced_pashtun == 1
    global mean4_1 = r(table)[1,1]

    * Without nondisplaced Pashtuns in the North
    reghdfe afghan_id displaced_pashtun nonpashtun_displaced nonpashtun_nondisplaced female ///
        age unemployed headhousehold married c.householdincome##c.householdincome if ///
        nondisplaced_pashtun_north == 0, abs(wave) vce(cluster distid)
    estimates store m4_3
    mean afghan_id if nondisplaced_pashtun_south == 1
    global mean4_3 = r(table)[1,1]

    * Comparing Pashtuns in the North to all others
    reghdfe afghan_id all_pashtun_north female age unemployed headhousehold married ///
        c.householdincome##c.householdincome, abs(provinceid#wave) vce(cluster distid)
    estimates store m4_4
    mean afghan_id if all_pashtun_north == 0
    global mean4_4 = r(table)[1,1]

    * Only including Afghanis in the North
    reghdfe afghan_id displaced_pashtun nonpashtun_displaced female age unemployed ///
        headhousehold married c.householdincome##c.householdincome if north_prov == 1, ///
        abs(provinceid#wave) vce(cluster distid)
    estimates store m4_5
    mean afghan_id if north_prov == 1 & displaced_pashtun == 0 & nonpashtun_displaced == 0
    global mean4_5 = r(table)[1,1]

    * Alternative measure
    reghdfe afghan_id displaced_pashtun2 nonpashtun_displaced nonpashtun_nondisplaced female ///
        age unemployed headhousehold married c.householdincome##c.householdincome, ///
        abs(provinceid#wave) vce(cluster distid)
    estimates store m4_6
    mean afghan_id if pashtun == 1 & displaced_pashtun2 == 0
    global mean4_6 = r(table)[1,1]

* 5. Muslim identity
    * Original analysis
    reghdfe religion_id displaced_pashtun nonpashtun_displaced nonpashtun_nondisplaced female ///
        age unemployed headhousehold married c.householdincome##c.householdincome, ///
        abs(provinceid#wave) vce(cluster distid)
    estimates store m5_1
    mean religion_id if nondisplaced_pashtun == 1
    global mean5_1 = r(table)[1,1]

    * Without nondisplaced Pashtuns in the North
    reghdfe religion_id displaced_pashtun nonpashtun_displaced nonpashtun_nondisplaced female ///
        age unemployed headhousehold married c.householdincome##c.householdincome if ///
        nondisplaced_pashtun_north == 0, abs(wave) vce(cluster distid)
    estimates store m5_3
    mean religion_id if nondisplaced_pashtun_south == 1
    global mean5_3 = r(table)[1,1]

    * Comparing Pashtuns in the North to all others
    reghdfe religion_id all_pashtun_north female age unemployed headhousehold married ///
        c.householdincome##c.householdincome, abs(provinceid#wave) vce(cluster distid)
    estimates store m5_4
    mean religion_id if all_pashtun_north == 0
    global mean5_4 = r(table)[1,1]

    * Only including Afghanis in the North
    reghdfe religion_id displaced_pashtun nonpashtun_displaced female age unemployed ///
        headhousehold married c.householdincome##c.householdincome if north_prov == 1, ///
        abs(provinceid#wave) vce(cluster distid)
    estimates store m5_5
    mean religion_id if north_prov == 1 & displaced_pashtun == 0 & nonpashtun_displaced == 0
    global mean5_5 = r(table)[1,1]

    * Alternative measure
    reghdfe religion_id displaced_pashtun2 nonpashtun_displaced nonpashtun_nondisplaced female ///
        age unemployed headhousehold married c.householdincome##c.householdincome, ///
        abs(provinceid#wave) vce(cluster distid)
    estimates store m5_6
    mean religion_id if pashtun == 1 & displaced_pashtun2 == 0
    global mean5_6 = r(table)[1,1]

*------------------------------------------------------------
* Table A23: Primary Identity Attachment
*------------------------------------------------------------
esttab m1_1 m2_1 m3_1 m4_1 m5_1, ///
    booktabs ///
    stats(provfe wavefe N, label("Province Fixed Effects?" "Survey Wave Fixed Effect?" "N")) ///
    varlabels(_cons Constant) ///
    starlevels(* 0.1 ** 0.05) ///
    mtitles("Family Identity Primary" "Ethnic Identity Primary" ///
            "Province/Region Identity Primary" "Afghan Identity Primary" ///
            "Muslim Identity Primary") ///
    nonumbers ///
    note("Robust standard errors clustered by districts and survey waves in parentheses.") ///
    se(2) b(3)

*------------------------------------------------------------
* Export to data/intermediate for plotting in R
*------------------------------------------------------------
esttab m1_1 m1_3 m1_4 m1_5 m1_6 m2_1 m2_3 m2_4 m2_5 m2_6 ///
       m3_1 m3_3 m3_4 m3_5 m3_6 m4_1 m4_3 m4_4 m4_5 m4_6 ///
       m5_1 m5_3 m5_4 m5_5 m5_6 using "replication/data/intermediate/MISTIresults.csv", ///
    cells(b(fmt(3)) se(fmt(3))) ///
    label mlabels("family_id1" "family_id3" "family_id4" "family_id5" "family_id6" ///
                  "ethnic_id1" "ethnic_id3" "ethnic_id4" "ethnic_id5" "ethnic_id6" ///
                  "local_id1" "local_id3" "local_id4" "local_id5" "local_id6" ///
                  "afghan_id1" "afghan_id3" "afghan_id4" "afghan_id5" "afghan_id6" ///
                  "religion_id1" "religion_id3" "religion_id4" "religion_id5" "religion_id6") ///
    csv

*------------------------------------------------------------
* Create matrix of means
*------------------------------------------------------------
matrix means = ($mean1_1, $mean1_3, $mean1_4, $mean1_5, $mean1_6, ///
                $mean2_1, $mean2_3, $mean2_4, $mean2_5, $mean2_6, ///
                $mean3_1, $mean3_3, $mean3_4, $mean3_5, $mean3_6, ///
                $mean4_1, $mean4_3, $mean4_4, $mean4_5, $mean4_6, ///
                $mean5_1, $mean5_3, $mean5_4, $mean5_5, $mean5_6)
matrix colnames means = family_id1 family_id3 family_id4 family_id5 family_id6 ///
                       ethnic_id1 ethnic_id3 ethnic_id4 ethnic_id5 ethnic_id6 ///
                       local_id1 local_id3 local_id4 local_id5 local_id6 ///
                       afghan_id1 afghan_id3 afghan_id4 afghan_id5 afghan_id6 ///
                       religion_id1 religion_id3 religion_id4 religion_id5 religion_id6
esttab matrix(means) using "replication/data/intermediate/MISTIresults_means.csv", replace

*------------------------------------------------------------
* Drop temporary macros
*------------------------------------------------------------
macro drop mean1_1
macro drop mean1_3
macro drop mean1_4
macro drop mean1_5
macro drop mean1_6
macro drop mean2_1
macro drop mean2_3
macro drop mean2_4
macro drop mean2_5
macro drop mean2_6
macro drop mean3_1
macro drop mean3_3
macro drop mean3_4
macro drop mean3_5
macro drop mean3_6
macro drop mean4_1
macro drop mean4_3
macro drop mean4_4
macro drop mean4_5
macro drop mean4_6
macro drop mean5_1
macro drop mean5_3
macro drop mean5_4
macro drop mean5_5
macro drop mean5_6
